var multiply = function (num1, num2) {
  let arr1 = [], arr2 = []
  if (num1.length < num2.length) {
    arr1 = num1.split('');
    arr2 = num2.split('');
  } else {
    arr1 = num2.split('');
    arr2 = num1.split('');
  }
  let l = arr1.length - 1;
  let temp = [];
  let more = 0;
  let carry;
  while (l >= 0) {
    carry = 0;
    let sum = [];
    for (let j = 1; j <= more; j++) {
      sum.unshift('0')
    }
    more++;
    for (let i = arr2.length - 1; i >= 0; i--) {
      sum.unshift((carry + Number(arr1[l]) * Number(arr2[i])) % 10 + '');
      carry = Math.floor((carry + Number(arr1[l] * Number(arr2[i]))) / 10);
    }
    if (carry !== 0)
      sum.unshift(carry + '')
    l--;
    // more.push('0');
    temp.push(sum)
  }
  console.log(temp);
  more = temp[0];
  for (let i = 1; i < temp.length; i++) {
    carry = 0;
    arr1 = [];
    l = more.length - 1
    let ll = temp[i].length - 1;
    while (l >= 0) {
      arr1.unshift((carry + Number(more[l]) + Number(temp[i][ll])) % 10 + '')
      carry = Math.floor((carry + Number(more[l]) + Number(temp[i][ll])) / 10);
      l--;
      ll--;
    }
    while (ll >= 0) {
      arr1.unshift((carry + Number(temp[i][ll])) % 10 + '')
      carry = Math.floor((carry + Number(temp[i][ll])) / 10);
      ll--;
    }
    if (carry != 0)
      arr1.unshift(carry + '');
    more = arr1;
  }
  // 最高位是0的话直接返回0
  if (more[0] === '0')
    return '0'
  else {
    temp = ''
    for (let i = 0; i < more.length; i++)
      temp += more[i];
    return temp
  }
};
// if (i == 8) {
//   console.log(more);
//   console.log(temp[i]);
// }
// while ()
//   if (more.length === temp[i].length) {
//     while (l >= 0) {
//       arr1.unshift((carry + Number(more[l]) + Number(temp[i][l])) % 10 + '')
//       carry = Math.floor((carry + Number(more[l]) + Number(temp[i][l])) / 10);
//       l--;
//     }
//     if (carry !== 0)
//       arr1.unshift(carry + '')
//   } else {
//     while (l >= 0) {
//       arr1.unshift((carry + Number(more[l]) + Number(temp[i][l + 1])) % 10 + '')
//       carry = Math.floor((carry + Number(more[l]) + Number(temp[i][l + 1])) / 10);
//       l--;
//     }
//     if (Number(temp[i][0]) + carry >= 10) {
//       arr1.unshift((Number(temp[i][0]) + carry) % 10 + '')
//       arr1.unshift((Number(temp[i][0]) + carry) / 10 + '')
//     } else {
//       arr1.unshift(Number(temp[i][0]) + carry + '')
//     }

//   }
console.log(multiply('123456789', '987654321'));
console.log(multiply('237', '284'));